package main.java.br.com.projeto.domain.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import main.java.br.com.projeto.domain.entity.Cliente;

public class DaoCliente extends Dao<Cliente>{

	/**
	 * 
	 */
	private static final long serialVersionUID = -6552547278427767418L;

	
	public DaoCliente() {
		super(Cliente.class);
	}
	
	public List<Cliente> listByFilter(Long id, String filter, String filterCpf) {
		String hql = "select cliente from Cliente cliente "
				+ "where (lower(cliente.nome) like '%' || lower ( cast(:filter as string) ) || '%' or :filter = null) "
				+ "and (cliente.id = :id or :id = 0) "
				+ "and (cliente.cpf like '%' || cast(:filterCpf  as string) || '%' or :filterCpf = null)";

		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("filter", filter);
		parameters.put("id", id);
		parameters.put("filterCpf", filterCpf);

		return this.findOneResult(hql, parameters);
	}
	
	public List<Cliente> listClientesByNome(String nome)
	{
		String hql = "select cliente from Cliente cliente "
				+ "where lower(cliente.nome) like '%' || lower ( cast(:nome as string) ) || '%' ";

		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("nome", nome);

		return this.findOneResult(hql, parameters);
	}
}
